﻿using CPPEI.ETL.DataServiceInterface;
using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using SER = CPPEI.ETL.Domain.Services;

namespace CPPEI.ETL.WebApi.DS
{
    /// <summary>
    /// 创建数据源
    /// </summary>
    [CPPEI.WebApi.AuthPostAction("DS", "CreateDataSource", "1.0")]
    public class CreateDataSourceAction : BaseAction<CreateSourceParams, CreateSourceResult>
    {
        protected override ActionResult<CreateSourceResult> OnExecute(ActionContext context, 
            SysParameters sysParameters,
            CreateSourceParams opParams)
        {
            SER.DtSerService dtSerService = new SER.DtSerService();
            ServiceResult result = dtSerService.CreateDtSource(context.UserId, opParams.DataServiceId, opParams.Name,
                opParams.Value,
                0,
                opParams.ParameterSettings,
                null,
                null);
            if(result.IsSuccess)
            {
                return new ActionResult<CreateSourceResult>(new CreateSourceResult());
            }
            else
            {
                return new ActionResult<CreateSourceResult>(result.IsSuccess, result.ErrorCode, result.Message, null);
            }
        }
    }

    public class CreateSourceParams
    {
        [Parameter]
        public string Name { get; set; }


        [Parameter]
        public Guid DataServiceId { get; set; }

        [Parameter]
        public string Value { get; set; }

        /// <summary>
        /// 参数设置name,type,defaultValue,desc
        /// </summary>
        [Parameter]
        public string ParameterSettings { get; set; }
    }

    public class CreateSourceResult
    {
    }
}
